package com.wlscale.roadsystem.modular;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.easy.component.component.toast.EasyToast;
import com.wlscale.roadsystem.R;
import com.wlscale.roadsystem.base.LZBaseActivity;
import com.wlscale.roadsystem.wiget.SwipeMenuListView.SwipeMenu;
import com.wlscale.roadsystem.wiget.SwipeMenuListView.SwipeMenuCreator;
import com.wlscale.roadsystem.wiget.SwipeMenuListView.SwipeMenuItem;
import com.wlscale.roadsystem.wiget.SwipeMenuListView.SwipeMenuListView;

public class TestActivtiy extends LZBaseActivity {
    private AppAdapter mAdapter;

    @Override
    public void initlayoutResID() {
        setContentView(R.layout.dialog_weight_correct_node_manage);
    }

    @Override
    public void initBundle() {

    }

    @Override
    public void initView() {
        SwipeMenuListView listView = (SwipeMenuListView) findViewById(R.id.listView);
        mAdapter = new AppAdapter();
        listView.setAdapter(mAdapter);


        SwipeMenuCreator creator = new SwipeMenuCreator() {

            @Override
            public void create(SwipeMenu menu) {
                // Create different menus depending on the view type
                createMenu1(menu);
            }
        };
        listView.setMenuCreator(creator);
// step 2. listener item click event
        listView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
                EasyToast.showShort(TestActivtiy.this,"ssss");
                return false;
            }
        });
    }


    @Override
    public void initHeader() {

    }

    @Override
    public void initLoadingView() {

    }

    @Override
    public void initData() {

    }


    private void createMenu1(SwipeMenu menu) {
        SwipeMenuItem item1 = new SwipeMenuItem(
                getApplicationContext());
        item1.setBackground(new ColorDrawable(Color.rgb(0xE5, 0x18,
                0x5E)));
        item1.setWidth(dp2px(90));
        item1.setIcon(R.mipmap.ic_launcher_round);
        menu.addMenuItem(item1);
    }




    private int dp2px(int dp) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
                getResources().getDisplayMetrics());
    }


    class AppAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return 10;
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public int getViewTypeCount() {
            // menu type count
            return 1;
        }

        @Override
        public int getItemViewType(int position) {
            // current menu type
            return position % 3;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = View.inflate(getApplicationContext(),
                        R.layout.item_correct_var_list, null);
                new ViewHolder(convertView);
            }
            ViewHolder holder = (ViewHolder) convertView.getTag();
            return convertView;
        }

        class ViewHolder {

            public ViewHolder(View view) {
                view.setTag(this);
            }
        }
    }

}
